import { APlugin } from '../types/common.interface';
import { TableDatas } from '../cors/table-datas';
import { Inject, Injectable, PluginInjectable } from '../decorators/inject';
import { Select } from '../cors/select';
import { ExecuteRecord } from '../cors/execute-record';
import { Hook } from '../cors/hook';
import { RowHeightCommand } from '../commands/row-height-command';
import { NExcel } from '../types';
import { Config } from '../cors/config';
import { createElement } from '../utils/dom-helper';
import { fromEvent } from 'rxjs';
import { filter } from 'rxjs/operators';
import './row-height.plugin.less';
import { EventHelper } from '../utils/event-helper';
import { RenderTrigger } from '../cors/render-trigger';
import { Cache } from '../cors/cache';
import { classTransformToObj, objTransformToClass } from '../decorators/toJSON';
import { DeleteRowCommand } from '../commands/delete-rows-command';
import { DeleteColCommand } from '../commands/delete-cols-command';
import { MergeCell } from '../cors/merge-cell';

@Injectable()
@PluginInjectable('DeleteRowColPlugin')
export class DeleteRowColPlugin extends APlugin {
    constructor(
        protected select: Select,
        protected conf: Config,
        protected tableData: TableDatas,
        protected render: RenderTrigger,
        protected executeRecord: ExecuteRecord,
        protected mergeCell: MergeCell
    ) {
        super();
    }
    public init() {

    }
    protected commandFactory(type: 'row'|'col', ids: number[]) {
        if(type === 'row') {
            return new DeleteRowCommand(this.tableData, this.render,this.conf, this.mergeCell, this.select, ids);
        } else {
            return new DeleteColCommand(this.tableData, this.render,this.conf, this.mergeCell, this.select, ids);
        }
    }
    public deleteRows(rows: number[]) {
        // console.log(rows);
        // let conf = classTransformToObj(this.conf);
        // console.log('conf',conf);
        // let data = classTransformToObj(this.tableData);
        // console.log('data', data);
        // let result = this.tableData.deleteRows(range);
        // let deleteResult = this.tableData.deleteRows(rows);
        // console.log(deleteResult)
        // let deletedRows = this.tableData.deleteRows(rows);
        // console.log(deletedRows);
        // this.render.triggerRenderAll();
        let command = this.commandFactory('row', rows);
        this.executeRecord.execute(command);
    }

    public deleteCols(cols: number[]) {
        let command = this.commandFactory('col', cols);
        this.executeRecord.execute(command);
    }
    public getSelectInfo() {
        return this.select.selected;
    }
    public getHiddenCols() {
        return Array.from(this.conf.hiddenCols);
    }
    public getHiddenRows() {
        return Array.from(this.conf.hiddenRows);
    }
    public destroy() {
        
    }
}